package ch1;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;


public class AmazonQuestion {

	/*
	 * Compare two lists of integers, return the elements that in both list.
	 * Since it requires that the return value should only contain unique element
	 * so I choose hashset to do the work. And the 
	 */
	public static List<Integer> intersection (List<Integer> a, List<Integer> b) {
		
		//Create a hashset
		HashSet<Integer> myA = new HashSet<Integer>();
		for(int i = 0; i != a.size(); ++i){
			myA.add(a.get(i));
		}
		HashSet<Integer> myCollection = new HashSet<Integer>();
		for(int i = 0; i != b.size(); ++i){
			int theCompare = b.get(i);
			if(myA.contains(theCompare)){
				myCollection.add(theCompare);
			}
		}
		
		return new ArrayList<Integer>(myCollection);

	}
	
	public static void main (String[] args){
		List<Integer> a = new ArrayList<Integer>();
		a.add(4);
		a.add(2);
		a.add(73);
		a.add(11);
		a.add(-5);
		List<Integer> b = new ArrayList<Integer>();
		b.add(-5);
		b.add(73);
		b.add(-1);
		b.add(9);
		b.add(9);
		b.add(4);
		b.add(7);
		List<Integer> c = intersection(a, b);
		for(int i = 0; i != c.size();++i){
			System.out.print(c.get(i) + " ");
		}
	}

}
